 /*
	本地存储, 存入json数据
	默认存储有效期为1h
*/
const storeOper = {
	set(k, v) {
		v.time = new Date().getTime();
		v.keep = v.keep || 1; // 单位为h
		window.localStorage.setItem(k, JSON.stringify(v));
	},
	get(k) {
		let storedStr = window.localStorage.getItem(k);
		let storedObj = JSON.parse(storedStr) || {};
		let curTime = new Date().getTime();
		let storeTime = storedObj.time;
		let disTime = curTime - storeTime;

		if (disTime >= storedObj.keep * 60 * 1000 * 1000) {
			storeOper.remove(k);
			return {};
		}

		return storedObj;
	},
	remove(k) {
		window.localStorage.removeItem(k);
	}
}

export default storeOper;